#include "util.h"


namespace dxy::easyWebServer
{

void setNoBlock(int src)
{
    int flag = fcntl(src, F_GETFL, nullptr);
    if(flag == -1) throw std::exception();
    int ret = fcntl(src, F_SETFL, flag | O_NONBLOCK);
    if(ret == -1) throw std::exception();
}

inline bool findChar(const std::string & src, const char c)
{
    auto it = src.find(c);
    if(it == std::string::npos)
    {
        return false;
    }
    return true;
}


void split(std::vector<std::string> & dst, const std::string & src, const std::string & tok)
{

}

void splitRegex(std::vector<std::string> & dst, const std::string & src, const std::string & patten)
{
    dst.clear();
    size_t pos = 0, startPos = 0;
    while(pos < src.size())
    {
        if(src[pos] == patten[0])
        {
            if(src.substr(pos, patten.size()) == patten)
            {
                dst.push_back(src.substr(startPos, pos - startPos));
                pos += patten.size();
                startPos = pos;
            }
            else
            {
                pos++;
                continue;
            }
        }
        else
        {
            pos++;
        }
    }
    dst.push_back(src.substr(startPos, src.size() - startPos));
}

}



